package org.t411.api.scrapper;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;


public class SearchOptionsStore {
	public Map<String, String> optionGroupNames; //Map<{id_groupe_doption}, {titre_groupe_doption}>
	public Map<String, Collection<SearchOption>> optionsInOptionsGroup; // Map<{id_groupe_doption}, {Collection}>
	
	public SearchOptionsStore() {
		this.optionGroupNames = new HashMap<String, String>();
		this.optionsInOptionsGroup = new HashMap<String, Collection<SearchOption>>();
	}
	
	public void addGroupOption(String title, String id, int qtOptions) {
		if (this.optionGroupNames.containsKey(id)) return;
		this.optionGroupNames.put(id, title);
		this.optionsInOptionsGroup.put(id, new ArrayList<SearchOption>(qtOptions));
	}
	
	public void addOption(String title, String id, String groupId) {
		this.optionsInOptionsGroup.get(groupId).add(new SearchOption(id, title, groupId));
	}
	
	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		
		for (Entry<String, String> aGroup : optionGroupNames.entrySet()) {
			result.append(aGroup.getValue()).append(" (").append(aGroup.getKey()).append(")\n");
			for (SearchOption aSetOption : optionsInOptionsGroup.get(aGroup.getKey())) {
				result.append('\t').append(aSetOption.name).append(" (").append(aSetOption.id).append(")\n");
			}
			result.append('\n');
		}
		
		return result.toString();
	}
}
